package com.lex.jfb;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


/**
 * Created by Administrator on 2016/5/31.
 */
public class ShiYong_YHQActivity extends Activity {
    private TextView couponValueTV,couponNameTV,couponRuleTV,couponValidTimeTV;
    private Button used_btn;
    private View suite_for_shop_btn,couponDetailPanel;
    private RedeemDialog verifyDialog;

    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_youhuiquan_xq);
        findView();
        initView();
    }

   protected void findView(){
       couponValueTV = (TextView) findViewById(R.id.coupon_value);
       couponNameTV = (TextView) findViewById(R.id.coupon_name);
       couponRuleTV = (TextView) findViewById(R.id.coupon_rule);
       couponValidTimeTV  = (TextView) findViewById(R.id.coupon_valid_time);
       used_btn = (Button) findViewById(R.id.used_btn);
       suite_for_shop_btn = findViewById(R.id.suite_for_shop_btn);
       couponDetailPanel = findViewById(R.id.coupon_detail_panel);
    }

    protected void onResume(){
        super.onResume();
        Intent intent = getIntent();
        try {
            couponValueTV.setText(intent.getStringExtra(YouHuiQ_XQActivity.KEY_COUPON_VALUE));
            couponNameTV.setText(intent.getStringExtra(YouHuiQ_XQActivity.KEY_COUPON_NAME));
            couponRuleTV.setText(intent.getStringExtra(YouHuiQ_XQActivity.KEY_COUPON_RULE));
            couponValidTimeTV.setText(intent.getStringExtra(YouHuiQ_XQActivity.KEY_COUPON_VALUE_TIME));
        } catch (Exception e){
            Log.e("lex","在优惠券详情页面获取传过来的信息出错");
        }
        couponDetailPanel.setEnabled(true);
        used_btn.setText(getString(R.string.use_right_now));
        used_btn.setEnabled(true);
    }
    protected void initView() {
        initDialog();
        used_btn.setOnClickListener(onClickListener);
        suite_for_shop_btn.setOnClickListener(onClickListener);
    }

    private void initDialog(){
        verifyDialog = new RedeemDialog(this);
        verifyDialog.setOnCouponUseSccueededLinstener(onCouponUseSccueededLinstener);
    }

    private RedeemDialog.OnCouponUseSccueededLinstener onCouponUseSccueededLinstener = new RedeemDialog.OnCouponUseSccueededLinstener() {
        @Override
        public void onCouponUseSeccueeded() {
            couponDetailPanel.setEnabled(false);
            used_btn.setText(getString(R.string.already_used));
            used_btn.setEnabled(false);
        }
    };
    private View.OnClickListener onClickListener = new View.OnClickListener(){
        public void onClick(View v){
            switch (v.getId()){
                case R.id.suite_for_shop_btn:
                    startActivity(new Intent(ShiYong_YHQActivity.this,ShiYong_MDActivity.class));
                    break;
                case R.id.used_btn:
                    verifyDialog.show();
                    break;
            }
        }
    };
}
